package com.leyou.comment.controller;


import com.leyou.comment.service.CommentsService;
import com.leyou.comments.entity.Comments;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author 林琼杨
 * @version 1.0
 * @date 2020/5/29 12:16
 */
@RestController
public class CommentsController {

    @Autowired
    private CommentsService commentsService;

    /**
     * 评价删除
     * @param id 评价id
     * @return
     */
    @DeleteMapping("/comments/delComments")
    public ResponseEntity<Void> delComments(@RequestParam("id") String id){
        commentsService.delComments(id);
        return ResponseEntity.ok().build();
    }

    /**
     * 商品评价
     * @param comments 商品评价信息
     * @return
     */
    @PostMapping("/comments/addComments")
    public ResponseEntity<Void> addComments(HttpServletRequest request, @RequestBody Comments comments){
        commentsService.addComments(request,comments);
        return ResponseEntity.status(HttpStatus.OK).build();
    }

    /**
     * 查询所有评论
     * @return
     */
    @GetMapping("/comments/findAddComments")
    public ResponseEntity<List<Comments>> findAddComments(@RequestParam("spuid")String spuid){
        List<Comments> comments = commentsService.findAddComments(spuid);
        return ResponseEntity.ok(comments);
    }
}
